package com.javaspeak.designpatterns.go4.structural.flyweight;

/**
 * References Shape. Shape is a flyweight object which can be used by many
 * CanvasElement instances.  The implementation for Shape encapsulates the
 * data required to render the underlying shape.  Shape does not
 * specify the coordinates of the Shape on the Canvas as different
 * CanvasElements are likely to position the shapes in different locations on
 * the Canvas.  Instead CanvasElement defines unique data such as the location
 * of the Shape on the Canvas.
 * <p>
 * The Shape is integral to the flyweight pattern.
 * Its data has been refactored out of CanvasElement into the Shape
 * implementation as it is identical data required by many instances.
 *
 * @author John Dickerson
 */
public class CanvasElement {

    private Shape shape;
    private int xcoordinate;
    private int ycoordinate;


    /**
     * Constructor
     *
     * @param shape  The flyweight instance to reference
     *
     * @param xcoordinate The X location of the Shape on the canvas
     *
     * @param ycoordinate The Y location of the Shape on the canvas
     */
    public CanvasElement( Shape shape, int xcoordinate, int ycoordinate ){

        this.shape = shape;
        this.xcoordinate = xcoordinate;
        this.ycoordinate = ycoordinate;
    }


    public Shape getShape() {

        return shape;
    }


    public int getXcoordinate() {

        return xcoordinate;
    }


    public int getYcoordinate() {

        return ycoordinate;
    }
}
